﻿

<Menu Vertical Style="MenuStyle.Pill" BackgroundColor="Color.Black" AdditionalStyle="overflow:auto;max-height:100vh;margin:0;width:230px !important">
    <Item>
        <ImageAnchor Link="/">
        <img src="img/logo.png" style="width:35px"/>
        </ImageAnchor>
        <Anchor Link="/">BlamanticUI</Anchor>
    </Item>
    <Item>
        <SelectList MaxItems="5" Size="Size.Small" Inverted Removable Fluid Filterable DataSource="SearchMenus" TItem="Navigation" TValue="string" OnItemSelected="SelectItem" ValueField="@nameof(Navigation.Name)" @bind-Value="SelectedLink">
            <DefaultItemContent>Keywords</DefaultItemContent>
            <ItemFormatContent>
                @context.Name
            </ItemFormatContent>
        </SelectList>
    </Item>
            <LinkItem Link="/">
                Getting Started
            </LinkItem>
            <LinkItem Link="https://github.com/AchievedOwner/BlamanticUI" target="_blank">
                <Icon IconClass="github"/> Github Repository
            </LinkItem>
    <Item>
        Common
        <SubMenu>
            @foreach (var item in Common)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
    <Item>
        Input
        <SubMenu>
            @foreach (var item in Input)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
    <Item>
        Layout
        <SubMenu>
            @foreach (var item in Layout)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
    <Item>
        Nav
        <SubMenu>
            @foreach (var item in Nav)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
    <Item>
        Data
        <SubMenu>
            @foreach (var item in Data)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
    <Item>
        Feedback
        <SubMenu>
            @foreach (var item in Feedback)
            {
                <LinkItem Link="@item.Link" Match="NavLinkMatch.All">
                    @item.Name
                </LinkItem>
            }
        </SubMenu>
    </Item>
</Menu>

@inject INavigationService NavService
@inject Microsoft.AspNetCore.Components.NavigationManager NavManager
@code {

    IEnumerable<Navigation> SearchMenus { get; set; }

    IEnumerable<Navigation> Common { get; set; }
    IEnumerable<Navigation> Input { get; set; }
    IEnumerable<Navigation> Layout { get; set; }
    IEnumerable<Navigation> Data { get; set; }
    IEnumerable<Navigation> Feedback { get; set; }
    IEnumerable<Navigation> Nav { get; set; }

    string SelectedLink { get; set; }

    protected override void OnInitialized()
    {
        Common = NavService.GetNavigations("Common");
        Input = NavService.GetNavigations("Input");
        Layout = NavService.GetNavigations("Layout");
        Data = NavService.GetNavigations("Data");
        Feedback = NavService.GetNavigations("Feedback");
        Nav = NavService.GetNavigations("Nav");

        SearchMenus = Common.Concat(Input).Concat(Layout).Concat(Data).Concat(Feedback).Concat(Nav).OrderBy(m => m.Name);
    }

    void SelectItem(Navigation item)
    {
        if (item == null)
        {
            return;
        }

        if (NavManager.Uri.Contains(item.Link))
        {
            return;
        }

        NavManager.NavigateTo(item.Link);
    }
}